namespace ASPNET.StarterKit.IssueTracker
{
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.VisualBasic.CompilerServices;

    public class ACR : UserControl
    {
        [AccessedThroughProperty("BankdetailGrd")]
        private DataGrid _BankdetailGrd;
        [AccessedThroughProperty("Btnselect")]
        private LinkButton _Btnselect;
        [AccessedThroughProperty("DataGrid1")]
        private DataGrid _DataGrid1;
        [AccessedThroughProperty("DropDownList1")]
        private DropDownList _DropDownList1;
        [AccessedThroughProperty("Textbusinessname")]
        private TextBox _Textbusinessname;
        [AccessedThroughProperty("TextChinesename")]
        private TextBox _TextChinesename;
        [AccessedThroughProperty("Textcity")]
        private TextBox _Textcity;
        [AccessedThroughProperty("Textcust")]
        private TextBox _Textcust;
        [AccessedThroughProperty("Textname")]
        private TextBox _Textname;

        public ACR()
        {
            base.Init += new EventHandler(this.Page_Init);
            base.Load += new EventHandler(this.Page_Load);
        }

        public void ApplyFilter_Click(object Sender, EventArgs E)
        {
            string CommandText;
            this.DataGrid1.CurrentPageIndex = 0;
            string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
            string custfilterValue = this.Textcust.Text.Replace("'", "''");
            string chinesenamefilterValue = this.TextChinesename.Text.Replace("'", "''");
            string namefilterValue = this.Textname.Text.Replace("'", "''");
            string cityfilterValue = this.Textcity.Text.Replace("'", "''");
            string ProvincefilterValue = this.DropDownList1.SelectedItem.Text.Replace("'", "''");
            string businessnamefilterValue = this.Textbusinessname.Text.Replace("'", "''");
            if (StringType.StrCmp(custfilterValue, "", false) != 0)
            {
                CommandText = "select acrcode, legal_name,Business_Name,CHname,city,Provincename from ACR_SAP where acrcode = '" + custfilterValue + "'";
            }
            else
            {
                CommandText = "select acrcode, legal_name,Business_Name,CHname,city,Provincename from ACR_SAP where acrcode like '%'";
            }
            if (StringType.StrCmp(namefilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and Legal_name like '%" + namefilterValue + "%' ";
            }
            if (StringType.StrCmp(chinesenamefilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and CHname like '%" + chinesenamefilterValue + "%' ";
            }
            if (StringType.StrCmp(cityfilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and city like '%" + cityfilterValue + "%' ";
            }
            if (StringType.StrCmp(ProvincefilterValue, "-- Province--", false) != 0)
            {
                CommandText = CommandText + "  and Provincename like '%" + ProvincefilterValue + "%' ";
            }
            if (StringType.StrCmp(businessnamefilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and Business_Name like '%" + businessnamefilterValue + "%'";
            }
            CommandText = CommandText + "order by acrcode desc";
            SqlConnection myConnection = new SqlConnection(ConnectionString);
            SqlDataAdapter myCommand = new SqlDataAdapter(CommandText, myConnection);
            DataSet ds = new DataSet();
            myCommand.Fill(ds);
            this.DataGrid1.DataSource = ds;
            this.DataGrid1.DataBind();
        }

        public void BindDataGrid1()
        {
            string CommandText;
            string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
            string custfilterValue = this.Textcust.Text.Replace("'", "''");
            string chinesenamefilterValue = this.TextChinesename.Text.Replace("'", "''");
            string namefilterValue = this.Textname.Text.Replace("'", "''");
            string cityfilterValue = this.Textcity.Text.Replace("'", "''");
            string ProvincefilterValue = this.DropDownList1.SelectedItem.Text.Replace("'", "''");
            string businessnamefilterValue = this.Textbusinessname.Text.Replace("'", "''");
            if (StringType.StrCmp(custfilterValue, "", false) != 0)
            {
                CommandText = "select acrcode, legal_name,Business_Name,CHname,city,Provincename from ACR_SAP where acrcode = '" + custfilterValue + "'";
            }
            else
            {
                CommandText = "select acrcode, legal_name,Business_Name,CHname,city,Provincename from ACR_SAP where acrcode like '%'";
            }
            if (StringType.StrCmp(namefilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and Legal_name like '%" + namefilterValue + "%' ";
            }
            if (StringType.StrCmp(chinesenamefilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and CHname like '%" + chinesenamefilterValue + "%' ";
            }
            if (StringType.StrCmp(cityfilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and city like '%" + cityfilterValue + "%' ";
            }
            if (StringType.StrCmp(ProvincefilterValue, "-- Province--", false) != 0)
            {
                CommandText = CommandText + "  and Provincename like '%" + ProvincefilterValue + "%' ";
            }
            if (StringType.StrCmp(businessnamefilterValue, "", false) != 0)
            {
                CommandText = CommandText + " and Business_Name like '%" + businessnamefilterValue + "%'";
            }
            CommandText = CommandText + "order by acrcode desc";
            SqlConnection myConnection = new SqlConnection(ConnectionString);
            SqlDataAdapter myCommand = new SqlDataAdapter(CommandText, myConnection);
            DataSet ds = new DataSet();
            myCommand.Fill(ds);
            this.DataGrid1.DataSource = ds;
            this.DataGrid1.DataBind();
        }

        public void BindDetailGrid()
        {
            if (this.DataGrid1.SelectedIndex != -1)
            {
                string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
                string filterValue = StringType.FromObject(this.DataGrid1.DataKeys[this.DataGrid1.SelectedIndex]).Replace("'", "''");
                string CommandText = "select ACRCODE,客户分类, 银行码, 银行帐户,纳税人登记号,贸易伙伴,地址 from BankDetails where ACRCODE = '" + filterValue + "'";
                SqlConnection myConnection = new SqlConnection(ConnectionString);
                SqlCommand myCommand = new SqlCommand(CommandText, myConnection);
                myConnection.Open();
                this.BankdetailGrd.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            }
            this.BankdetailGrd.DataBind();
        }

        public void DataGrid_Page(object Sender, DataGridPageChangedEventArgs E)
        {
            if (this.DataGrid1.SelectedIndex != -1)
            {
                this.DataGrid1.SelectedIndex = -1;
                this.BindDetailGrid();
            }
            this.DataGrid1.CurrentPageIndex = E.NewPageIndex;
            this.BindDataGrid1();
        }

        public void DataGrid_Select(object Sender, EventArgs E)
        {
            this.BindDetailGrid();
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
                string CommandText = "select distinct Provincename from ACR_SAP where  Provincename IS NOT NULL order by Provincename";
                SqlConnection myConnection = new SqlConnection(ConnectionString);
                SqlCommand myCommand = new SqlCommand(CommandText, myConnection);
                this.DropDownList1.DataTextField = "Provincename";
                myConnection.Open();
                this.DropDownList1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                this.DropDownList1.DataBind();
                this.DropDownList1.Items.Insert(0, "-- Province--");
            }
        }

        protected virtual DataGrid BankdetailGrd
        {
            get
            {
                return this._BankdetailGrd;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._BankdetailGrd != null)
                {
                }
                this._BankdetailGrd = value;
                if (this._BankdetailGrd != null)
                {
                }
            }
        }

        protected virtual LinkButton Btnselect
        {
            get
            {
                return this._Btnselect;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Btnselect != null)
                {
                }
                this._Btnselect = value;
                if (this._Btnselect != null)
                {
                }
            }
        }

        protected virtual DataGrid DataGrid1
        {
            get
            {
                return this._DataGrid1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._DataGrid1 != null)
                {
                }
                this._DataGrid1 = value;
                if (this._DataGrid1 != null)
                {
                }
            }
        }

        protected virtual DropDownList DropDownList1
        {
            get
            {
                return this._DropDownList1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._DropDownList1 != null)
                {
                }
                this._DropDownList1 = value;
                if (this._DropDownList1 != null)
                {
                }
            }
        }

        protected virtual TextBox Textbusinessname
        {
            get
            {
                return this._Textbusinessname;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Textbusinessname != null)
                {
                }
                this._Textbusinessname = value;
                if (this._Textbusinessname != null)
                {
                }
            }
        }

        protected virtual TextBox TextChinesename
        {
            get
            {
                return this._TextChinesename;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._TextChinesename != null)
                {
                }
                this._TextChinesename = value;
                if (this._TextChinesename != null)
                {
                }
            }
        }

        protected virtual TextBox Textcity
        {
            get
            {
                return this._Textcity;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Textcity != null)
                {
                }
                this._Textcity = value;
                if (this._Textcity != null)
                {
                }
            }
        }

        protected virtual TextBox Textcust
        {
            get
            {
                return this._Textcust;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Textcust != null)
                {
                }
                this._Textcust = value;
                if (this._Textcust != null)
                {
                }
            }
        }

        protected virtual TextBox Textname
        {
            get
            {
                return this._Textname;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Textname != null)
                {
                }
                this._Textname = value;
                if (this._Textname != null)
                {
                }
            }
        }
    }
}

